package com.example.myproject.model;

// 在model/CustomUserDetails.java

// 在model/CustomUserDetails.java

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public class CustomUserDetails implements UserDetails {
    private String username;
    private String password;
    private Collection<? extends GrantedAuthority> authorities;
    private Map<Long, List<String>> contractRoles;

    public CustomUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities, Map<Long, List<String>> contractRoles) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
        this.contractRoles = contractRoles;
    }

    public Map<Long, List<String>> getContractIds() {
        return contractRoles;
    }

    // 实现 UserDetails 的其他方法
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public Map<Long, List<String>> getContractRoles() {
        return contractRoles;
    }
}

